package labox.innovation.netcore;

/**
 * 发送数据包抽象模型
 * 
 */
public abstract class SendablePacket<T extends MMOClient<?>> extends AbstractPacket<T> {

	protected final void writeInt(int value) {
		_buf.putInt(value);
	}

	protected final void writeDouble(double value) {
		_buf.putDouble(value);
	}

	protected final void writeFloat(float value) {
		_buf.putFloat(value);
	}

	protected final void writeByte(int data) {
		_buf.put((byte) data);
	}

	protected final void writeShort(int value) {
		_buf.putShort((short) value);
	}

	protected final void writeLong(long value) {
		_buf.putLong(value);
	}

	protected final void writeData(byte[] data) {
		_buf.put(data);
	}

	protected final void writeString(String text) {
		int len=0;
		byte[] strBytes;
		if (text == null) {
			_buf.putShort((short) len);
		}else{
			strBytes=text.getBytes(encoding);
			len=strBytes.length;
			_buf.putShort((short) len);
			for(int i=0;i<len;i++){
				_buf.put(strBytes[i]);
			}
		}
	
	}

	protected abstract void write();
}